package principle.lsp.code.before;

/**
 * RectangleDemo
 *
 * @author l56jq
 * @since 2023/11/6 16:45
 */
public class RectangleDemo {
    public static void main(String[] args) {
        // 如果改变成正方形，代码就会一直执行，无法结束，所以这套代码不符合里氏替换原则
        // Rectangle rectangle = new Square();
        Rectangle rectangle = new Rectangle();
        rectangle.setLength(20);
        rectangle.setWidth(10);
        resize(rectangle);
        printLengthAndWidth(rectangle);
    }


    // 扩宽方法
    public static void resize(Rectangle rectangle) {
        while (rectangle.getWidth() <= rectangle.getLength()) {
            rectangle.setWidth(rectangle.getWidth() + 1);
        }
    }

    public static void printLengthAndWidth(Rectangle rectangle) {
        System.out.println("宽度：" + rectangle.getWidth());
        System.out.println("长度：" + rectangle.getLength());

    }

}
